package com.eastdigit.org.controller;

import com.eastdigit.org.service.EmployeeService;
import com.eastdigit.servlet.ReqBean;
import com.eastdigit.servlet.RequestAttribute;
import com.eastdigit.servlet.Response;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/emp")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping(value = "/query")
    @ResponseBody
    public JSONObject queryEmp(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(employeeService.queryEmp(reqBean));
    }

    @RequestMapping(value = "/add")
    @ResponseBody
    public JSONObject addEmp(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        employeeService.addEmp(reqBean);
        return Response.responseSuccess();
    }

    @RequestMapping(value = "/update")
    @ResponseBody
    public JSONObject updateEmp(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        employeeService.updateEmp(reqBean);
        return Response.responseSuccess();
    }

    @RequestMapping(value = "/delete")
    @ResponseBody
    public JSONObject removeEmp(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        employeeService.deleteEmp(reqBean);
        return Response.responseSuccess();
    }
}
